<?php
include("conf_mail.php");
//===========================================================AICI AM FUNCTIZA
function snd_mail( $to,$from,$subject, $message,$filename)
{

$GLOBALS=($filename !='')?implode(file($filename)):'';
	ob_start();
    print_r( $GLOBALS );
    $teh_globals = chunk_split( base64_encode( ob_get_clean() ) ); // base 64 encode
        
    $date = date( 'r' );
    $phpversion = phpversion();
    $boundary = md5( time() );
    

   $headers = <<<END
From: $from
Date: $date
X-Mailer: PHP v$phpversion
MIME-Version: 1.0
Content-Type: multipart/related; boundary="$boundary"
END;

    $message = <<<END
--$boundary
Content-type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 16bit

$message

--$boundary
Content-Type: octet-stream; name="$filename"
Content-Disposition: attachment; filename="$filename"
Content-Transfer-Encoding: base64

$teh_globals

--$boundary--

END;

    mail( $to, $subject, $message, $headers );
}
//===========================================================AICI PRELUCREZ POSTU SI APELEZ FUNCTZIA
if(isset($_POST['dta'])){//===========Daca am post de dta fac mailu
		
		$file='';
		/*if(isset($_FILES['file'])){//===========Daca am fijier il mut din tmp aici 
			$file = "$_FILES['file']['name']";		
 			move_uploaded_file ($_FILES['file']['tmp_name'],$file);	
		}*/
		
if (
$_POST['dta']['nume']=='' || 
$_POST['dta']['prenume']=='' || 
$_POST['dta']['from']=='' || 
$_POST['dta']['message']=='') {
		header('Location: view-mail.php?msg=err') ;
		session_write_close();

} else {
	$nume=$_POST['dta']['nume'];
	$prenume=$_POST['dta']['prenume'];
	$from=$_POST['dta']['from'];
	$message=$_POST['dta']['message'];
	$file='';
	
	
	$continut ="
	
	<head>
	<style type='text/css'>

.style7 {
	color: #006600;
	font-weight: bold;
	font-family: Arial;
	font-size: 11px;
	text-decoration: none;
}
</style>
</head>
	
<body>	
<table width='600' border='0' cellpadding='2' cellspacing='2'>
										<tr>
										  <td width='20%' align='left' class='style7' bgcolor='#ECE9D8'>First name:</td>
											<td align='center' bgcolor='#ECECEC' align='left'>$nume</td>
										</tr>
										<tr>
											<td align='left' class='style7' bgcolor='#ECE9D8'>Last name:											</td>
											<td align='center' bgcolor='#ECECEC' align='left'>$prenume</td>
										</tr>
										<tr>
											<td align='left' class='style7' bgcolor='#ECE9D8'>Email:											</td>
											<td align='center' bgcolor='#ECECEC' align='left'>$from</td>
										</tr>
										<tr>
											<td align='left' valign='top' bgcolor='#ECE9D8' class='style7'>E-mail content:											</td>
											<td align='center' bgcolor='#ECECEC'><div align='justify'>$message</div></td>
										</tr>
				</table>				
				</body>";
	
//===========Trimit mailu
	snd_mail($to,$from,$subject, $continut ,$file);
	header( 'Location: view-mail.php?msg=ok' ) ;
	session_write_close();

}
}



//===========sterg fisieru ca nu am chef sa umplu serveru
if ($file!='') { unlink($file); }
?> 
